package com.dzl.admin;

import com.dzl.admin.pojo.vo.LoginSysAdminVo;
import com.dzl.base.controller.BaseController;
import com.dzl.admin.pojo.vo.SysMenuVo;
import com.dzl.admin.service.SysMenuService;
import com.dzl.config.exception.CommonException;
import com.dzl.util.EmptyUtils;
import com.dzl.util.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 功能描述：菜单信息管理Controller
 * @author: wangchao
 * @date: 2021/5/11 18:02
 */
@Api(value = "菜单信息管理", tags = "菜单信息管理")
@RestController
@RequestMapping("/menu")
public class SysMenuController extends BaseController {

    @Autowired
    private SysMenuService menuService;

    /**
     * 描述:获取所有菜单树
     * @date 2021/5/13 11:01
     * @author wangchao
     * @Param []
     * @return com.dzl.util.JsonResult<java.util.List<com.dzl.menu.pojo.vo.MenuVo>> 菜单树返回对象
    **/
    @ApiOperation(value = "获取所有菜单树", notes = "获取所有菜单树")
    @GetMapping("/queryMenuTree")
    public JsonResult<List<SysMenuVo>> queryMenuTree(){
        try {
            //获取当前登录用户角色
            LoginSysAdminVo adminVo = getAdminInfo();
            if(adminVo==null){
                throw new CommonException("登录信息已失效");
            }
            Integer isEnable = null;
            //当企业配置为同步平台，则isEnable传1隐藏商品管理等菜单
            if(EmptyUtils.isEmpty(adminVo.getAppRuleConfig())){
                isEnable = 1;
            }
            return JsonResult.success(menuService.queryMenuTree(isEnable));
        }catch (Exception e){
            e.printStackTrace();
        }
        return JsonResult.fail();
    }
}
